package com.sleep.psy.external_server.business.resourse.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sleep.psy.external_server.business.resourse.entity.QuestAnswer;
import com.sleep.psy.external_server.business.resourse.mapper.QuestAnswerMapper;
import com.sleep.psy.external_server.business.resourse.service.QuestAnswerService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 调查问卷选项表 服务实现类
 * </p>
 *
 * @author wenliguo
 * @since 2025-08-12
 */
@Service
public class QuestAnswerServiceImpl extends ServiceImpl<QuestAnswerMapper, QuestAnswer> implements QuestAnswerService {

    protected Logger logger = LoggerFactory.getLogger(QuestAnswerService.class);

    @Autowired
    private QuestAnswerMapper questAnswerMapper;

    /**
     * 获取答案
     * @author wenliguo
     * @date 2025/6/5 10:50
     * @return java.util.Map<java.lang.String,java.util.List<com.sleep.psy.main_server.business2.scale.entity.QuestAnswer>>
     */
    @Override
    public Map<String, List<QuestAnswer>> getAnserMap() {
        Map<String, List<QuestAnswer>> reMap = new HashMap<>();
        QueryWrapper<QuestAnswer> wrapper = new QueryWrapper<>();
        List<QuestAnswer> dbList = questAnswerMapper.selectList(wrapper);
        String qid = "";
        List<QuestAnswer> answerList = null;
        for (QuestAnswer answer : dbList) {
            //key
            qid = answer.getQid() + "";
            if (reMap.containsKey(qid)) {
                reMap.get(qid).add(answer);
            } else {
                //value
                answerList = new ArrayList<>();
                answerList.add(answer);
                reMap.put(qid, answerList);
            }
        }
        return reMap;
    }
}
